package testdemo;
//对话功能
import com.alibaba.fastjson.JSONObject;
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import okhttp3.*;

import java.io.IOException;
import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {

        // 直接在代码中设置访问密钥和密钥
        String accessKey = "ALTAKtcDh0nQtP40NgZUAmDA4K";
        String secretKey = "57a949833c7b408a81e06959785d90cf";
        Scanner cin=new Scanner(System.in);
        Qianfan qianfan = new Qianfan(accessKey, secretKey);

        while(true) {
            System.out.print("HANDSOME BOY:");
            String content=cin.nextLine();
            ChatResponse response = qianfan.chatCompletion()

                    .model("ERNIE-4.0-8K-0104") // 使用model指定预置模型
                    .addMessage("user",content ) // 添加用户消息
                    .temperature(0.7) // 自定义超参数
                    .execute(); // 发起请求
            System.out.print("AI:");
            System.out.println(response.getResult());


        }
    }

}
